
#ifndef TDDNS_H
#define TDDNS_H
    #include "Arduino.h"
    #include "ESPDateTime.h"
    #include <UrlEncode.h>
    #include <ArduinoJson.h>
    #include <ESP8266HTTPClient.h>
    #include <WiFiClient.h>
    #include "sha1.h"
    #include <ESP8266WiFi.h>
    #include "./I_TDDNS_Client.h"


// Handler to notify user about new public IP
typedef std::function<void(const char* old_ip, const char* new_ip)> TDDNSUpdateHandler;
// Handler to notify user about error
typedef std::function<void(const char* error)> TDDNSErrorHandler;

class TDDNS {
    public:
    TDDNS();
    ~TDDNS();
    
    void client(I_TDDNS_Client *client);
    void update();

    // Callback
    void onUpdate(TDDNSUpdateHandler handler) {
      _ddnsUpdateFunc = handler;
    }
    void onError(TDDNSErrorHandler handler) {
      _ddnsErrorFunc = handler;
    }

  private:
    TDDNSUpdateHandler _ddnsUpdateFunc = nullptr;
    TDDNSErrorHandler _ddnsErrorFunc = nullptr;
    unsigned long interval;
    unsigned long previousMillis;
    I_TDDNS_Client *ddns_client;
    String new_ip;
    String old_ip;
    String ddns_id;
    String ddns_secret;
    String ddns_domain;
    String ddns_choice;
};
#endif